#version 460
#pragma vp_name VP Vertex Shader Main 

// Vertex stage globals:
int oe_terrain_vertexMarker; 
float atmos_space; 
float oe_layer_opacity; 
float oe_rex_morphFactor; 
vec2 oe_layer_texc; 
vec2 oe_layer_texcParent; 
vec2 oe_normal_uv; 
vec3 atmos_atten; 
vec3 atmos_color; 
vec3 atmos_lightDir; 
vec3 atmos_up; 
vec3 oe_UpVectorView; 
vec3 oe_normal_binormal; 
vec3 vp_Normal; 
vec3 vp_VertexView; 
vec4 oe_layer_tilec; 
vec4 vp_Color; 
vec4 vp_Vertex; 

// Vertex stage outputs:
out VP_PerVertex { 
    flat int oe_terrain_vertexMarker; 
    float atmos_space; 
    float oe_layer_opacity; 
    float oe_rex_morphFactor; 
    vec2 oe_layer_texc; 
    vec2 oe_layer_texcParent; 
    vec2 oe_normal_uv; 
    vec3 atmos_atten; 
    vec3 atmos_color; 
    vec3 atmos_lightDir; 
    vec3 atmos_up; 
    vec3 oe_UpVectorView; 
    vec3 oe_normal_binormal; 
    vec3 vp_Normal; 
    vec3 vp_VertexView; 
    vec4 oe_layer_tilec; 
    vec4 vp_Color; 
    vec4 vp_Vertex; 
} vp_out; 

// Function declarations:
void oe_rex_init_model(inout vec4); 
void oe_rex_morph(inout vec4); 
void myfunc_vertexmodel(inout vec4); 
void oe_VisibleLayer_initOpacity(inout vec4); 
void myfunc_vertextranform_m2v();
void oe_rex_init_view(inout vec4); 
void oe_rex_applyElevation(inout vec4); 
void oe_rex_imageLayer_VS(inout vec4); 
void oe_rex_normalMapVS(inout vec4); 
void myfunc_vertexview(inout vec4); 
void atmos_vertex_main(inout vec4); 
void oe_ClipPlane_vs(inout vec4); 
void myfunc_vertextranform_m2v();
void myfunc_vertexclip(inout vec4); 

void main(void) 
{ 
    vp_Vertex = gl_Vertex; 
    vp_Normal = gl_Normal; 
    vp_Color  = gl_Color; 
    oe_rex_init_model(vp_Vertex); 
    oe_rex_morph(vp_Vertex); 
    myfunc_vertexmodel(vp_Vertex); //////////////////////
    oe_VisibleLayer_initOpacity(vp_Vertex); 
    myfunc_vertextranform_m2v();/////////////////////////
	   // 上面这个函数的放置位置在LOCATION_VERTEX_TRANSFORM_MODEL_TO_VIEW
	   // 时，osgEarth会自动去掉这个函数的参数，所以上面这个函数干脆不带参数，
	   // 同时引入这个位置的函数后，会去掉两行代码（L1，L2）
	   // vp_Vertex = gl_ModelViewMatrix * vp_Vertex;        //L1
    // vp_Normal = normalize(gl_NormalMatrix * vp_Normal);//L2
	   // 也就是说如果在这个位置使用自定义函数，那么开发者就必须自己
	   // 实现model到view的矩阵变换，包括vertex和normal的变换。
	
    vp_VertexView = vp_Vertex.xyz;
    oe_rex_init_view(vp_Vertex); 
    oe_rex_applyElevation(vp_Vertex); 
    oe_rex_imageLayer_VS(vp_Vertex); 
    oe_rex_normalMapVS(vp_Vertex); 
    myfunc_vertexview(vp_Vertex); /////////////////////////
    atmos_vertex_main(vp_Vertex); 
    oe_ClipPlane_vs(vp_Vertex); 
    vp_Vertex = gl_ProjectionMatrix * vp_Vertex; 
    myfunc_vertexclip(vp_Vertex); ////////////////////////
    gl_Position = vp_Vertex; 
    vp_out.oe_terrain_vertexMarker = oe_terrain_vertexMarker; 
    vp_out.atmos_space = atmos_space; 
    vp_out.oe_layer_opacity = oe_layer_opacity; 
    vp_out.oe_rex_morphFactor = oe_rex_morphFactor; 
    vp_out.oe_layer_texc = oe_layer_texc; 
    vp_out.oe_layer_texcParent = oe_layer_texcParent; 
    vp_out.oe_normal_uv = oe_normal_uv; 
    vp_out.atmos_atten = atmos_atten; 
    vp_out.atmos_color = atmos_color; 
    vp_out.atmos_lightDir = atmos_lightDir; 
    vp_out.atmos_up = atmos_up; 
    vp_out.oe_UpVectorView = oe_UpVectorView; 
    vp_out.oe_normal_binormal = oe_normal_binormal; 
    vp_out.vp_Normal = vp_Normal; 
    vp_out.vp_VertexView = vp_VertexView; 
    vp_out.oe_layer_tilec = oe_layer_tilec; 
    vp_out.vp_Color = vp_Color; 
    vp_out.vp_Vertex = vp_Vertex; 
}